{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Python and Friends\n",
    "\n",
    "This is a very quick run-through of some python syntax"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# The %... is an iPython thing, and is not part of the Python language.\n",
    "# In this case we're just telling the plotting library to draw things on\n",
    "# the notebook, instead of on a separate window.\n",
    "%matplotlib inline \n",
    "#this line above prepares IPython notebook for working with matplotlib\n",
    "\n",
    "# See all the \"as ...\" contructs? They're just aliasing the package names.\n",
    "# That way we can call methods like plt.plot() instead of matplotlib.pyplot.plot().\n",
    "\n",
    "import numpy as np # imports a fast numerical programming library\n",
    "import scipy as sp #imports stats functions, amongst other things\n",
    "import matplotlib as mpl # this actually imports matplotlib\n",
    "import matplotlib.cm as cm #allows us easy access to colormaps\n",
    "import matplotlib.pyplot as plt #sets up plotting under plt\n",
    "import pandas as pd #lets us handle data as dataframes\n",
    "#sets up pandas table display\n",
    "pd.set_option('display.width', 500)\n",
    "pd.set_option('display.max_columns', 100)\n",
    "pd.set_option('display.notebook_repr_html', True)\n",
    "import seaborn as sns #sets up styles and gives us more plotting options"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##The Python Language\n",
    "\n",
    "Lets talk about using Python as a calculator..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1+2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Notice integer division and floating-point error below!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0, 0.5, 9.600000000000001)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1/2,1.0/2.0,3*3.2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here is how we can print things. Something on the last line by itself is returned as the output value."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4.0 \n",
      "1.66666666667\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print 1+3.0,\"\\n\",5/3.0\n",
    "5/3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can obtain the type of a variable, and use boolean comparisons tontest these types."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.833333333333\n",
      "<type 'float'>\n"
     ]
    }
   ],
   "source": [
    "a=5.0/6.0\n",
    "print(a)\n",
    "print type(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import types\n",
    "type(a)==types.FloatType"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(a)==types.IntType"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Python and Iteration (and files)\n",
    "\n",
    "In working with python I always remember: a python is a duck.\n",
    "\n",
    "What I mean is, python has a certain way of doing things. For example lets call one of these ways listiness. Listiness works on lists, dictionaries, files, and a general notion of something called an iterator.\n",
    "\n",
    "But first, lets introduce the notion of a comprehension. Its a way of constructing a list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alist=[1,2,3,4,5]\n",
    "asquaredlist=[i*i for i in alist]\n",
    "asquaredlist"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Python has some nifty functions like `enumerate` and `zip`. The former gives a list of tuples with each tuple of the form `(index, value)`, while the latter takes elements from each list and outs them together into a tuple, thus creating a list of tuples. The first is a duck, but the second isnt."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(<enumerate at 0x108fb0410>, [(1, 1), (2, 4), (3, 9), (4, 16), (5, 25)])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "enumerate(asquaredlist),zip(alist, asquaredlist)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Someone realized that design flaw and created izip."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<itertools.izip at 0x108fafb48>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from itertools import izip\n",
    "izip(alist, asquaredlist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<enumerate object at 0x108fb05f0>\n"
     ]
    }
   ],
   "source": [
    "print enumerate(asquaredlist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(0, 1), (1, 4), (2, 9), (3, 16), (4, 25)]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[k for k in enumerate(asquaredlist)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Open files behave like lists too! Here we get each line in the file and find its length, using the comprehension syntax to put these lengths into a big list."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[9, 27, 2, 24, 2, 2, 2, 2, 22, 2, 28, 60, 29, 28, 27, 22, 22, 24, 25, 18, 24, 11, 21, 20, 22, 32, 10, 28, 31, 12, 22, 27, 2, 51, 32, 2, 67, 13, 2, 18, 2, 2, 2, 8, 2, 50, 2, 49, 2, 6, 14, 2, 7, 45, 2, 6, 21, 2, 7, 11, 2, 6, 5, 2, 7, 41, 2, 6, 53, 2, 7, 48, 25, 2, 6, 27, 2, 7, 23, 2, 6, 19, 39, 46, 2, 7, 48, 2, 32, 2, 6, 25, 2, 6, 27, 2, 7, 22, 2, 6, 30, 24, 2, 7, 24, 22, 2, 9, 2, 6, 18, 2, 6, 6, 25, 2, 6, 17, 2, 6, 45, 2, 6, 47, 2, 6, 22, 2, 6, 36, 42, 48, 38, 45, 37, 42, 2, 6, 32, 2, 6, 18, 41, 42, 31, 2, 6, 20, 41, 2, 6, 20, 51, 51, 43, 30, 2, 6, 51, 2, 23, 2, 6, 48, 2, 6, 43, 2, 6, 47, 2, 6, 49, 2, 6, 23, 2, 6, 23, 2, 6, 50, 42, 40, 54, 2, 6, 17, 2, 6, 22, 2, 6, 42, 2, 15, 2, 6, 33, 2, 6, 46, 42, 22, 2, 6, 41, 38, 19, 2, 6, 26, 2, 6, 25, 36, 40, 45, 42, 15, 2, 6, 48, 47, 2, 6, 48, 44, 48, 2, 6, 49, 47, 43, 43, 41, 50, 43, 46, 50, 30, 2, 6, 13, 47, 42, 44, 45, 53, 53, 53, 36, 50, 45, 39, 43, 35, 50, 39, 49, 36, 47, 41, 39, 48, 42, 39, 46, 45, 41, 50, 44, 2, 6, 37, 47, 49, 45, 2, 6, 41, 43, 41, 51, 45, 50, 43, 47, 43, 48, 42, 39, 45, 38, 46, 2, 19, 2, 53, 42, 14, 40, 44, 14, 42, 40, 11, 39, 41, 53, 19, 53, 2, 6, 40, 2, 6, 27, 2, 6, 12, 2, 6, 12, 2, 6, 12, 2, 15, 2, 38, 35, 38, 39, 2, 6, 44, 2, 6, 42, 38, 44, 48, 43, 42, 40, 41, 37, 2, 6, 38, 46, 44, 45, 49, 51, 48, 42, 2, 6, 45, 45, 47, 42, 42, 39, 45, 47, 44, 2, 6, 45, 44, 2, 11, 2, 2, 2, 52, 2, 63, 35, 2, 7, 47, 46, 52, 38, 47, 42, 41, 47, 47, 43, 42, 52, 45, 42, 45, 46, 47, 39, 46, 44, 46, 47, 40, 44, 49, 47, 47, 41, 43, 44, 46, 46, 43, 42, 45, 41, 48, 34, 49, 2, 16, 47, 2, 7, 41, 2, 35, 2, 45, 47, 41, 54, 45, 43, 42, 46, 34, 2, 7, 16, 44, 49, 37, 42, 50, 49, 2, 7, 51, 2, 6, 47, 37, 41, 41, 2, 7, 45, 45, 41, 2, 6, 54, 2, 7, 46, 2, 6, 44, 2, 8, 43, 50, 38, 40, 53, 37, 2, 6, 26, 2, 8, 11, 39, 2, 6, 45, 44, 38, 41, 40, 41, 49, 48, 45, 44, 47, 2, 7, 52, 47, 48, 53, 37, 43, 38, 46, 43, 40, 41, 44, 40, 43, 48, 46, 43, 48, 48, 48, 40, 45, 43, 35, 46, 41, 40, 38, 39, 43, 45, 2, 8, 46, 49, 2, 6, 41, 2, 7, 38, 41, 43, 45, 45, 48, 52, 41, 2, 26, 2, 6, 45, 38, 39, 49, 42, 40, 43, 53, 49, 50, 41, 46, 46, 47, 45, 38, 47, 55, 45, 47, 46, 48, 54, 49, 37, 44, 43, 46, 43, 40, 49, 2, 43, 2, 6, 24, 2, 6, 28, 34, 2, 6, 48, 2, 6, 54, 47, 12, 2, 6, 17, 2, 6, 47, 47, 2, 6, 37, 2, 6, 37, 40, 39, 45, 38, 47, 2, 6, 47, 2, 6, 43, 44, 2, 6, 41, 2, 6, 50, 47, 42, 41, 39, 2, 6, 17, 2, 6, 28, 2, 6, 39, 2, 6, 40, 39, 2, 6, 41, 2, 6, 10, 2, 6, 32, 2, 6, 21, 2, 6, 35, 41, 38, 21, 2, 6, 29, 2, 6, 42, 40, 43, 51, 35, 43, 49, 45, 55, 39, 46, 38, 49, 45, 50, 43, 32, 2, 6, 21, 2, 6, 46, 2, 6, 26, 2, 6, 17, 45, 39, 43, 43, 43, 30, 2, 6, 20, 2, 6, 44, 43, 24, 2, 6, 45, 30, 2, 15, 17, 2, 6, 17, 2, 7, 17, 2, 6, 18, 2, 7, 29, 2, 6, 28, 2, 6, 41, 2, 6, 29, 2, 6, 45, 2, 6, 14, 2, 6, 17, 2, 6, 30, 2, 6, 18, 2, 6, 27, 2, 6, 32, 2, 6, 39, 2, 6, 53, 2, 15, 17, 2, 6, 19, 2, 6, 30, 2, 6, 40, 19, 2, 6, 24, 30, 2, 6, 20, 2, 6, 40, 50, 43, 44, 42, 41, 42, 46, 46, 17, 2, 6, 26, 2, 6, 39, 2, 44, 2, 46, 52, 53, 53, 2, 9, 2, 2, 2, 40, 2, 30, 2, 7, 40, 40, 40, 27, 2, 6, 20, 2, 7, 45, 40, 40, 45, 41, 10, 2, 6, 17, 2, 7, 19, 43, 46, 41, 46, 42, 44, 49, 41, 37, 46, 44, 48, 42, 55, 42, 39, 47, 45, 46, 45, 50, 32, 44, 45, 39, 38, 39, 46, 44, 44, 41, 42, 41, 48, 2, 6, 45, 48, 40, 45, 47, 47, 29, 2, 7, 17, 45, 2, 19, 2, 38, 38, 2, 6, 47, 45, 56, 2, 38, 2, 38, 51, 41, 43, 52, 49, 45, 48, 42, 45, 46, 52, 40, 46, 40, 49, 45, 37, 44, 44, 45, 43, 42, 44, 2, 7, 42, 2, 6, 47, 2, 7, 38, 26, 2, 6, 27, 44, 2, 7, 11, 2, 9, 2, 6, 42, 2, 6, 52, 2, 6, 24, 39, 45, 53, 37, 46, 43, 45, 44, 2, 6, 45, 25, 2, 6, 47, 41, 47, 2, 6, 46, 2, 6, 47, 49, 54, 48, 45, 2, 6, 42, 24, 2, 6, 44, 2, 6, 52, 42, 2, 6, 45, 45, 48, 48, 45, 44, 47, 40, 44, 43, 38, 41, 50, 47, 39, 44, 43, 51, 40, 48, 42, 2, 6, 24, 2, 11, 2, 2, 2, 25, 2, 41, 2, 6, 42, 2, 6, 35, 2, 6, 16, 2, 6, 29, 2, 6, 19, 2, 6, 52, 43, 2, 57, 2, 31, 2, 6, 50, 52, 49, 43, 28, 2, 6, 17, 2, 6, 18, 43, 41, 50, 39, 47, 50, 42, 52, 39, 37, 48, 50, 42, 39, 50, 46, 50, 43, 45, 48, 35, 46, 46, 42, 21, 2, 6, 26, 2, 16, 2, 6, 44, 46, 55, 38, 42, 51, 41, 41, 44, 48, 39, 41, 44, 49, 43, 46, 38, 48, 49, 2, 25, 2, 6, 36, 37, 15, 2, 6, 33, 40, 24, 2, 6, 18, 2, 6, 43, 2, 6, 18, 2, 6, 31, 38, 42, 35, 43, 2, 6, 49, 40, 42, 43, 49, 41, 42, 39, 38, 28, 2, 6, 22, 26, 2, 6, 28, 2, 6, 22, 2, 6, 29, 2, 6, 20, 42, 40, 2, 18, 2, 45, 2, 28, 2, 53, 40, 2, 28, 2, 6, 38, 2, 6, 46, 2, 6, 44, 2, 6, 46, 2, 6, 24, 2, 6, 24, 2, 11, 2, 2, 2, 44, 2, 27, 2, 6, 55, 2, 8, 10, 2, 6, 9, 2, 8, 25, 44, 24, 2, 6, 19, 2, 8, 43, 25, 2, 6, 28, 2, 8, 47, 2, 6, 7, 2, 8, 27, 46, 44, 48, 49, 41, 43, 51, 58, 41, 42, 41, 37, 53, 43, 2, 6, 8, 2, 8, 45, 2, 6, 9, 2, 8, 41, 45, 2, 6, 49, 40, 26, 2, 8, 18, 47, 42, 51, 46, 49, 36, 44, 46, 22, 2, 6, 22, 13, 2, 8, 45, 54, 45, 41, 45, 41, 41, 45, 43, 45, 19, 40, 48, 44, 37, 22, 45, 47, 36, 38, 41, 40, 39, 40, 48, 43, 41, 43, 47, 41, 48, 21, 44, 50, 41, 37, 43, 39, 42, 43, 37, 39, 40, 47, 48, 46, 49, 42, 41, 36, 2, 9, 2, 6, 47, 51, 43, 41, 48, 42, 34, 42, 51, 42, 42, 41, 46, 26, 46, 39, 50, 47, 2, 12, 2, 43, 36, 17, 2, 6, 31, 2, 6, 26, 2, 6, 30, 2, 6, 11, 2, 6, 34, 2, 6, 39, 2, 32, 2, 6, 26, 2, 6, 21, 2, 6, 15, 2, 6, 24, 2, 6, 23, 2, 6, 28, 2, 6, 17, 2, 6, 55, 23, 2, 15, 25, 2, 6, 49, 27, 2, 6, 52, 18, 2, 6, 35, 43, 45, 54, 41, 43, 25, 2, 6, 49, 2, 6, 38, 23, 2, 6, 30, 2, 6, 47, 52, 46, 45, 49, 45, 27, 2, 6, 30, 2, 6, 47, 2, 15, 23, 2, 6, 19, 2, 6, 11, 17, 2, 6, 27, 2, 6, 16, 2, 6, 34, 2, 6, 32, 2, 8, 19, 2, 6, 58, 52, 19, 2, 6, 28, 2, 6, 44, 20, 2, 8, 19, 2, 6, 47, 25, 41, 45, 20, 2, 8, 19, 2, 6, 55, 51, 2, 6, 48, 2, 6, 46, 53, 40, 13, 44, 44, 45, 35, 49, 48, 44, 60, 62, 39, 48, 48, 8, 2, 8, 19, 2, 6, 47, 42, 37, 51, 53, 46, 44, 41, 31, 2, 11, 2, 2, 2, 9, 2, 38, 2, 32, 2, 6, 48, 2, 6, 18, 2, 6, 48, 39, 19, 2, 6, 27, 2, 6, 50, 46, 52, 45, 46, 48, 45, 53, 46, 47, 2, 6, 25, 2, 6, 50, 40, 43, 48, 42, 46, 40, 23, 2, 6, 21, 2, 6, 50, 31, 2, 6, 36, 2, 6, 48, 42, 34, 59, 43, 41, 36, 21, 2, 6, 22, 2, 6, 31, 2, 6, 14, 20, 2, 6, 30, 41, 43, 51, 11, 46, 44, 45, 41, 50, 41, 21, 2, 6, 21, 2, 6, 67, 64, 2, 6, 56, 13, 2, 6, 44, 50, 38, 56, 49, 45, 43, 39, 14, 50, 40, 42, 38, 38, 46, 2, 6, 18, 2, 6, 32, 2, 6, 15, 2, 6, 38, 2, 6, 19, 2, 6, 28, 2, 6, 16, 2, 6, 11, 2, 18, 2, 18, 2, 38, 2, 6, 43, 2, 6, 32, 2, 6, 41, 46, 45, 42, 51, 39, 38, 43, 2, 6, 19, 2, 6, 25, 25, 2, 6, 15, 2, 6, 44, 44, 45, 37, 41, 41, 48, 42, 40, 46, 45, 45, 46, 43, 2, 6, 44, 35, 40, 47, 36, 46, 50, 2, 6, 44, 36, 19, 2, 6, 25, 47, 51, 51, 34, 42, 38, 46, 57, 45, 2, 11, 2, 2, 2, 33, 2, 58, 2, 7, 45, 44, 41, 45, 43, 43, 43, 54, 44, 39, 51, 51, 48, 40, 45, 41, 50, 39, 2, 8, 45, 44, 48, 41, 40, 40, 43, 31, 2, 6, 21, 47, 44, 19, 2, 7, 15, 47, 41, 18, 2, 7, 46, 2, 8, 46, 38, 44, 44, 2, 7, 45, 30, 2, 8, 11, 2, 58, 2, 19, 2, 6, 44, 24, 2, 7, 47, 2, 6, 45, 36, 41, 45, 39, 43, 36, 2, 7, 43, 2, 6, 43, 49, 2, 7, 46, 2, 18, 2, 44, 50, 2, 8, 40, 48, 2, 7, 26, 2, 49, 2, 27, 47, 2, 7, 44, 41, 44, 41, 41, 50, 42, 47, 43, 44, 39, 49, 40, 48, 46, 42, 41, 18, 45, 45, 41, 26, 2, 7, 19, 45, 39, 50, 49, 20, 2, 35, 2, 6, 32, 38, 39, 51, 49, 46, 51, 42, 44, 43, 18, 2, 8, 29, 2, 6, 37, 49, 44, 41, 44, 44, 42, 43, 42, 10, 48, 39, 46, 10, 60, 13, 61, 35, 10, 44, 2, 8, 31, 2, 6, 46, 10, 35, 36, 30, 30, 63, 67, 12, 67, 15, 49, 39, 48, 24, 2, 7, 18, 20, 2, 6, 26, 2, 7, 38, 2, 6, 50, 46, 42, 47, 44, 41, 45, 45, 49, 43, 46, 50, 47, 41, 47, 44, 40, 44, 49, 40, 22, 2, 7, 25, 2, 8, 25, 2, 6, 52, 40, 27, 2, 7, 18, 2, 6, 44, 36, 39, 47, 20, 2, 7, 28, 2, 6, 48, 20, 2, 8, 20, 2, 6, 47, 36, 41, 43, 37, 30, 2, 7, 17, 2, 8, 53, 2, 6, 35, 46, 2, 39, 2, 26, 2, 31, 2, 6, 20, 2, 6, 26, 2, 6, 38, 2, 6, 17, 2, 6, 40, 2, 6, 18, 2, 6, 61, 29, 2, 6, 28, 2, 6, 65, 32, 2, 6, 18, 2, 6, 64, 52, 2, 6, 67, 64, 65, 65, 16, 2, 6, 22, 2, 6, 30, 2, 6, 14, 2, 6, 44, 2, 6, 63, 61, 61, 65, 67, 62, 64, 2, 6, 64, 40, 2, 6, 16, 2, 6, 65, 64, 64, 67, 67, 18, 2, 6, 57, 67, 7, 2, 6, 25, 2, 6, 26, 2, 39, 2, 6, 46, 2, 6, 35, 2, 18, 2, 7, 19, 2, 6, 20, 2, 6, 61, 41, 2, 6, 43, 2, 7, 38, 46, 2, 6, 28, 2, 6, 19, 2, 6, 56, 10, 2, 7, 25, 2, 6, 56, 28, 2, 6, 51, 2, 6, 58, 62, 64, 9, 2, 7, 18, 2, 6, 21, 2, 6, 24, 2, 6, 60, 43, 2, 6, 27, 2, 6, 62, 56, 2, 6, 65, 7, 2, 6, 61, 61, 2, 7, 63, 48, 2, 6, 33, 2, 6, 64, 30, 2, 6, 64, 64, 23, 2, 17, 22, 2, 6, 57, 62, 65, 23, 2, 6, 43, 2, 6, 62, 66, 58, 64, 2, 7, 30, 2, 6, 59, 67, 65, 20, 2, 6, 23, 2, 6, 63, 59, 64, 66, 38, 2, 6, 34, 2, 6, 65, 10, 2, 7, 28, 2, 6, 60, 60, 66, 64, 64, 67, 66, 64, 65, 60, 62, 64, 67, 66, 53, 2, 6, 50, 2, 6, 60, 2, 6, 59, 65, 62, 2, 6, 61, 67, 65, 63, 63, 63, 7, 2, 6, 56, 25, 2, 6, 54, 46, 2, 6, 57, 13, 2, 6, 61, 29, 2, 6, 27, 2, 6, 35, 2, 6, 62, 66, 65, 67, 65, 27, 2, 6, 58, 63, 57, 67, 66, 31, 2, 6, 64, 62, 66, 32, 2, 6, 16, 2, 7, 50, 2, 6, 28, 2, 6, 55, 2, 6, 62, 65, 67, 67, 31, 2, 32, 2, 7, 24, 2, 6, 63, 64, 63, 60, 64, 31, 2, 7, 24, 2, 6, 61, 29, 2, 19, 2, 6, 30, 2, 6, 67, 66, 2, 6, 64, 23, 2, 6, 67, 53, 2, 6, 35, 2, 6, 64, 9, 2, 6, 38, 2, 6, 13, 2, 6, 19, 2, 6, 36, 2, 6, 59, 59, 66, 64, 67, 15, 2, 6, 58, 2, 6, 32, 2, 6, 7, 37, 38, 2, 2, 6, 32, 2, 6, 38, 2, 6, 60, 20, 2, 6, 24, 2, 6, 30, 2, 6, 7, 26, 21, 45, 65, 28, 2, 31, 2, 64, 62, 60, 61, 63, 62, 67, 60, 64, 51, 2, 9, 23, 2, 6, 63, 65, 66, 67, 67, 64, 64, 61, 62, 67, 67, 64, 61, 2, 49, 2, 43, 2, 46, 49, 48, 53, 44, 44, 53, 50, 45, 54, 44, 51, 32, 2, 18, 2, 6, 60, 13, 2, 9, 23, 53, 48, 43, 51, 50, 53, 48, 49, 52, 42, 51, 44, 48, 17, 45, 52, 49, 48, 52, 44, 44, 47, 51, 26, 52, 43, 53, 53, 29, 2, 6, 19, 2, 6, 64, 65, 12, 2, 9, 49, 2, 6, 21, 2, 6, 38, 2, 9, 53, 46, 49, 45, 49, 53, 59, 49, 46, 51, 50, 49, 54, 29, 2, 6, 64, 27, 2, 6, 62, 62, 67, 65, 51, 2, 6, 53, 2, 6, 53, 64, 65, 28, 2, 6, 13, 2, 6, 51, 2, 55, 2, 60, 11, 2, 9, 14, 2, 6, 60, 66, 29, 2, 9, 14, 2, 6, 58, 2, 22, 2, 61, 37, 2, 6, 15, 2, 40, 2, 6, 24, 17, 41, 44, 42, 44, 45, 45, 48, 49, 13, 40, 48, 43, 50, 48, 42, 43, 38, 8, 40, 45, 41, 40, 42, 46, 46, 55, 48, 46, 40, 40, 43, 49, 56, 15, 44, 44, 44, 48, 38, 13, 49, 43, 39, 43, 42, 50, 53, 45, 44, 47, 47, 44, 46, 41, 43, 41, 48, 48, 2, 9, 2, 2, 2, 2, 10, 2, 32, 2, 57, 16, 2, 7, 43, 45, 42, 38, 2, 6, 46, 48, 2, 7, 43, 41, 47, 20, 2, 8, 26, 2, 6, 24, 2, 7, 43, 2, 6, 43, 25, 2, 8, 19, 17, 2, 6, 44, 50, 41, 42, 42, 32, 2, 6, 17, 47, 29, 2, 7, 48, 28, 42, 45, 2, 6, 20, 2, 40, 2, 7, 31, 45, 42, 18, 43, 48, 42, 38, 42, 27, 2, 8, 21, 39, 44, 52, 41, 23, 2, 6, 23, 2, 15, 2, 6, 51, 61, 42, 50, 52, 35, 20, 2, 7, 28, 55, 51, 45, 42, 17, 2, 6, 45, 2, 29, 2, 17, 2, 6, 47, 43, 45, 44, 49, 39, 48, 45, 45, 53, 50, 45, 41, 38, 50, 51, 46, 41, 43, 40, 51, 40, 48, 44, 42, 45, 41, 46, 39, 49, 43, 45, 45, 42, 28, 2, 6, 15, 43, 2, 6, 39, 2, 6, 39, 40, 31, 2, 6, 12, 25, 2, 6, 48, 49, 51, 41, 47, 17, 2, 6, 25, 2, 6, 10, 2, 6, 15, 2, 6, 27, 2, 6, 62, 27, 2, 6, 64, 2, 6, 58, 65, 66, 55, 2, 6, 42, 2, 6, 55, 64, 6, 2, 6, 26, 2, 6, 57, 65, 67, 66, 63, 67, 66, 60, 9, 2, 6, 19, 2, 6, 59, 39, 2, 6, 33, 2, 6, 65, 66, 64, 63, 63, 11, 2, 6, 33, 2, 6, 59, 67, 66, 67, 63, 66, 29, 2, 9, 2, 6, 42, 59, 44, 45, 52, 43, 42, 47, 50, 48, 37, 48, 2, 31, 2, 7, 44, 52, 53, 42, 43, 44, 31, 51, 42, 42, 36, 45, 48, 47, 2, 6, 40, 42, 48, 45, 46, 41, 44, 47, 47, 47, 43, 31, 2, 7, 17, 46, 2, 11, 2, 2, 2, 33, 2, 37, 2, 6, 58, 64, 65, 60, 62, 52, 65, 67, 67, 65, 67, 52, 2, 11, 24, 2, 6, 62, 66, 63, 66, 63, 64, 64, 66, 60, 62, 65, 65, 59, 64, 60, 64, 25, 2, 11, 58, 2, 6, 62, 63, 63, 64, 65, 64, 17, 2, 19, 2, 50, 2, 58, 2, 6, 40, 2, 6, 29, 2, 18, 2, 35, 2, 16, 19, 2, 25, 2, 6, 20, 2, 18, 2, 6, 36, 2, 6, 38, 39, 2, 6, 20, 2, 6, 30, 44, 45, 60, 46, 43, 50, 48, 44, 50, 49, 42, 52, 49, 47, 49, 50, 47, 46, 43, 46, 47, 47, 40, 43, 39, 41, 33, 44, 41, 45, 28, 2, 6, 16, 52, 44, 2, 6, 46, 18, 2, 66, 41, 2, 7, 30, 2, 6, 62, 45, 2, 7, 62, 7, 2, 6, 67, 21, 2, 6, 54, 2, 6, 21, 2, 6, 64, 12, 2, 6, 65, 20, 2, 6, 44, 2, 8, 41, 2, 6, 48, 2, 6, 41, 2, 6, 32, 33, 2, 6, 14, 2, 6, 32, 2, 6, 14, 2, 6, 39, 2, 6, 27, 2, 6, 51, 2, 6, 19, 2, 6, 10, 2, 6, 25, 2, 6, 9, 2, 6, 14, 2, 6, 60, 65, 22, 2, 6, 38, 2, 6, 62, 66, 66, 67, 62, 57, 2, 41, 2, 62, 60, 59, 57, 63, 66, 66, 61, 64, 67, 43, 2, 11, 2, 6, 27, 2, 6, 53, 2, 6, 52, 2, 19, 2, 6, 64, 19, 2, 6, 39, 2, 6, 61, 50, 2, 6, 53, 2, 6, 33, 36, 35, 2, 6, 44, 2, 6, 22, 2, 6, 18, 2, 29, 2, 10, 49, 47, 44, 50, 49, 39, 2, 11, 39, 44, 42, 47, 46, 43, 43, 36, 49, 41, 52, 56, 2, 10, 50, 48, 48, 42, 27, 2, 11, 23, 47, 38, 47, 2, 6, 30, 2, 11, 41, 48, 38, 39, 2, 10, 44, 40, 37, 38, 51, 40, 36, 45, 42, 44, 37, 46, 48, 47, 49, 54, 43, 50, 51, 45, 41, 46, 43, 33, 38, 40, 40, 52, 43, 51, 2, 11, 46, 46, 40, 42, 43, 46, 47, 35, 2, 6, 43, 2, 10, 49, 48, 29, 11, 2, 11, 23, 44, 2, 9, 2, 6, 32, 2, 8, 39, 2, 6, 30, 2, 7, 56, 2, 6, 61, 8, 2, 7, 28, 2, 6, 58, 63, 65, 61, 66, 14, 2, 19, 2, 43, 2, 6, 33, 2, 6, 61, 23, 2, 6, 38, 2, 6, 51, 2, 6, 26, 2, 6, 62, 64, 22, 2, 6, 58, 46, 49, 52, 37, 38, 2, 45, 2, 6, 64, 62, 66, 2, 6, 17, 2, 6, 33, 2, 8, 20, 2, 6, 21, 2, 7, 28, 2, 6, 25, 2, 38, 2, 6, 40, 30, 48, 32, 66, 62, 60, 2, 6, 15, 2, 6, 22, 38, 32, 41, 28, 2, 6, 24, 2, 6, 59, 24, 2, 6, 21, 2, 6, 35, 2, 6, 27, 2, 6, 51, 41, 45, 19, 2, 39, 2, 7, 45, 2, 6, 23, 2, 7, 17, 2, 6, 23, 2, 7, 48, 2, 6, 18, 2, 7, 34, 2, 6, 63, 62, 34, 2, 7, 61, 31, 2, 6, 29, 2, 7, 61, 22, 2, 6, 18, 2, 7, 61, 65, 62, 34, 2, 6, 16, 2, 7, 16, 2, 6, 64, 65, 65, 8, 2, 6, 57, 27, 2, 6, 65, 50, 2, 6, 64, 2, 6, 60, 24, 2, 6, 32, 2, 6, 51, 2, 6, 64, 63, 14, 2, 6, 26, 2, 6, 62, 33, 2, 6, 64, 8, 2, 41, 2, 67, 66, 14, 2, 7, 63, 2, 6, 62, 2, 7, 20, 2, 6, 13, 2, 7, 23, 2, 6, 19, 2, 7, 34, 2, 6, 56, 63, 63, 2, 7, 59, 21, 2, 6, 61, 64, 63, 64, 63, 65, 65, 26, 2, 19, 2, 21, 2, 6, 57, 2, 6, 60, 2, 6, 44, 2, 6, 31, 2, 6, 29, 2, 6, 18, 2, 6, 20, 2, 6, 63, 41, 2, 6, 16, 2, 9, 2, 6, 27, 2, 18, 2, 22, 2, 41, 2, 43, 53, 55, 40, 51, 44, 41, 33, 44, 45, 39, 45, 2, 9, 2, 2, 2, 34, 2, 46, 2, 7, 44, 50, 44, 41, 40, 39, 22, 2, 7, 28, 36, 37, 39, 2, 6, 40, 47, 45, 45, 41, 43, 46, 43, 49, 50, 42, 42, 46, 2, 7, 45, 41, 33, 2, 15, 19, 2, 25, 2, 19, 2, 6, 45, 37, 56, 43, 50, 50, 50, 39, 27, 2, 7, 23, 2, 18, 2, 45, 43, 38, 41, 45, 43, 45, 44, 50, 47, 48, 40, 48, 40, 44, 47, 49, 44, 48, 44, 45, 41, 45, 43, 42, 47, 49, 47, 45, 43, 41, 43, 44, 45, 57, 41, 18, 2, 23, 2, 17, 2, 6, 43, 47, 47, 42, 44, 12, 42, 43, 51, 50, 48, 48, 41, 46, 5, 46, 42, 43, 40, 41, 51, 46, 44, 43, 2, 9, 2, 32, 2, 7, 44, 44, 2, 9, 2, 2, 2, 39, 2, 29, 2, 6, 50, 55, 53, 47, 30, 2, 6, 35, 2, 8, 19, 44, 2, 35, 2, 17, 2, 6, 33, 2, 8, 45, 2, 6, 43, 2, 8, 45, 2, 6, 44, 2, 8, 23, 2, 6, 24, 2, 8, 21, 2, 6, 26, 51, 49, 2, 8, 50, 2, 6, 52, 38, 43, 2, 8, 47, 17, 2, 6, 39, 2, 6, 26, 25, 2, 35, 2, 6, 26, 2, 19, 2, 8, 28, 2, 6, 34, 2, 25, 2, 8, 41, 2, 6, 45, 44, 2, 8, 17, 2, 6, 28, 48, 16, 47, 47, 52, 46, 36, 40, 45, 2, 8, 51, 30, 2, 6, 13, 44, 44, 45, 47, 43, 40, 41, 47, 39, 44, 29, 2, 8, 18, 48, 2, 6, 45, 46, 43, 46, 44, 35, 39, 35, 43, 39, 52, 44, 48, 48, 45, 42, 48, 48, 54, 53, 42, 44, 41, 49, 46, 46, 48, 40, 20, 47, 43, 40, 45, 46, 43, 26, 2, 8, 26, 43, 46, 32, 2, 6, 18, 39, 48, 23, 2, 8, 25, 46, 24, 2, 6, 27, 46, 42, 40, 45, 27, 2, 8, 10, 2, 6, 33, 2, 16, 2, 44, 56, 2, 8, 17, 2, 6, 42, 46, 45, 9, 2, 8, 32, 44, 42, 46, 46, 23, 2, 6, 27, 2, 8, 26, 39, 48, 46, 45, 45, 42, 42, 46, 2, 6, 46, 52, 48, 43, 42, 51, 2, 8, 28, 2, 6, 27, 2, 8, 40, 2, 6, 27, 2, 8, 28, 2, 6, 47, 38, 50, 2, 15, 2, 8, 41, 32, 21, 2, 6, 10, 49, 49, 44, 46, 47, 46, 48, 47, 44, 45, 44, 45, 49, 41, 40, 45, 2, 8, 46, 2, 6, 38, 41, 45, 38, 46, 41, 42, 37, 41, 40, 45, 48, 45, 47, 41, 47, 25, 45, 43, 44, 41, 47, 35, 46, 27, 2, 8, 18, 2, 6, 43, 44, 49, 43, 51, 40, 39, 49, 48, 42, 46, 38, 38, 46, 41, 31, 2, 8, 46, 47, 28, 2, 6, 35, 2, 8, 8, 37, 2, 6, 53, 46, 47, 41, 40, 49, 45, 48, 46, 32, 46, 46, 49, 42, 46, 21, 2, 52, 2, 2, 2, 9, 2, 32, 2, 52, 2, 7, 54, 50, 20, 2, 8, 41, 2, 48, 2, 46, 2, 7, 34, 2, 8, 44, 43, 42, 45, 42, 26, 2, 7, 15, 44, 40, 39, 47, 41, 54, 46, 44, 40, 40, 45, 2, 8, 40, 43, 33, 47, 2, 7, 24, 45, 48, 40, 49, 2, 42, 2, 50, 40, 51, 49, 45, 2, 40, 2, 51, 43, 47, 42, 38, 51, 43, 40, 2, 11, 2, 39, 2, 17, 2, 6, 16, 2, 16, 32, 2, 6, 53, 2, 39, 2, 6, 50, 2, 6, 44, 2, 6, 49, 28, 2, 6, 20, 2, 6, 15, 2, 6, 64, 67, 12, 2, 6, 36, 2, 6, 61, 64, 64, 66, 65, 8, 2, 6, 32, 2, 6, 60, 2, 6, 63, 11, 2, 6, 63, 24, 2, 7, 19, 2, 6, 55, 2, 11, 2, 2, 2, 40, 2, 24, 2, 7, 47, 47, 44, 41, 49, 55, 53, 40, 44, 38, 16, 2, 22, 2, 30, 2, 6, 43, 25, 2, 7, 18, 2, 6, 51, 2, 7, 22, 2, 6, 37, 2, 34, 2, 7, 32, 2, 6, 12, 2, 7, 19, 2, 6, 53, 65, 65, 66, 64, 10, 2, 7, 13, 2, 6, 63, 41, 2, 7, 30, 2, 6, 62, 23, 2, 7, 20, 2, 6, 64, 66, 65, 28, 2, 7, 42, 2, 6, 29, 2, 22, 2, 7, 49, 41, 54, 50, 42, 45, 14, 2, 6, 14, 2, 7, 13, 2, 6, 7, 2, 7, 41, 2, 6, 59, 24, 2, 7, 28, 2, 6, 63, 51, 2, 9, 2, 7, 50, 45, 41, 54, 2, 40, 2, 51, 48, 43, 42, 47, 47, 38, 46, 43, 47, 44, 2, 9, 2, 2, 2, 31, 2, 42, 2, 6, 45, 43, 43, 44, 42, 39, 22, 2, 7, 23, 2, 6, 15, 2, 31, 2, 48, 2, 6, 35, 2, 7, 26, 2, 6, 32, 2, 7, 30, 2, 6, 25, 2, 7, 39, 2, 6, 42, 23, 2, 7, 39, 40, 41, 48, 41, 42, 2, 6, 44, 2, 7, 32, 2, 6, 47, 45, 50, 48, 45, 2, 7, 22, 2, 9, 2, 6, 32, 2, 6, 48, 2, 26, 2, 40, 42, 42, 45, 49, 39, 36, 42, 42, 43, 54, 45, 45, 54, 47, 45, 38, 44, 38, 36, 46, 44, 40, 40, 48, 46, 40, 46, 43, 40, 48, 43, 40, 46, 45, 2, 9, 2, 2, 2, 42, 2, 28, 2, 8, 28, 2, 7, 38, 32, 2, 8, 22, 2, 7, 47, 61, 53, 51, 38, 44, 51, 57, 53, 42, 53, 46, 2, 8, 18, 2, 17, 2, 43, 46, 39, 42, 2, 34, 2, 6, 44, 2, 8, 19, 2, 15, 37, 24, 33, 28, 2, 8, 43, 2, 6, 31, 10, 31, 27, 36, 28, 2, 8, 20, 2, 6, 17, 10, 43, 2, 15, 2, 8, 27, 2, 6, 10, 37, 37, 30, 2, 7, 26, 2, 6, 62, 67, 13, 2, 7, 26, 2, 6, 67, 25, 10, 39, 34, 33, 28, 2, 44, 35, 37, 27, 2, 7, 17, 2, 6, 53, 10, 33, 32, 43, 34, 2, 38, 30, 40, 40, 2, 7, 30, 2, 6, 59, 66, 63, 66, 33, 2, 9, 2, 7, 52, 2, 17, 2, 49, 52, 48, 45, 49, 45, 58, 56, 45, 45, 51, 44, 44, 47, 41, 48, 40, 42, 43, 43, 29, 2, 19, 2, 8, 28, 2, 7, 49, 2, 22, 2, 21, 2, 7, 25, 37, 46, 40, 51, 42, 37, 40, 46, 52, 40, 2, 8, 45, 44, 2, 19, 2, 7, 22, 2, 42, 2, 7, 51, 2, 8, 20, 2, 7, 28, 2, 8, 19, 2, 33, 2, 7, 49, 20, 2, 8, 23, 2, 7, 54, 47, 47, 20, 2, 7, 29, 43, 47, 42, 45, 45, 54, 13, 2, 7, 21, 2, 7, 7, 2, 8, 17, 2, 7, 26, 2, 7, 45, 51, 47, 45, 45, 44, 31, 2, 7, 21, 2, 7, 29, 46, 32, 2, 7, 15, 37, 56, 54, 19, 2, 7, 23, 2, 7, 26, 2, 7, 49, 44, 28, 2, 7, 20, 41, 45, 39, 43, 26, 2, 8, 27, 2, 7, 30, 2, 58, 11, 2, 51, 46, 49, 46, 42, 46, 43, 46, 43, 27, 2, 6, 10, 40, 35, 43, 2, 25, 2, 7, 50, 25, 2, 6, 59, 67, 20, 2, 7, 34, 2, 6, 55, 54, 2, 7, 58, 2, 6, 63, 58, 67, 67, 49, 10, 43, 2, 7, 47, 40, 2, 6, 10, 32, 32, 26, 27, 30, 2, 36, 29, 30, 29, 31, 2, 57, 2, 9, 2, 7, 25, 2, 7, 42, 37, 51, 50, 36, 49, 49, 37, 45, 44, 25, 2, 7, 17, 43, 49, 41, 50, 33, 2, 7, 15, 50, 24, 2, 11, 2, 2, 2, 39, 2, 32, 2, 6, 41, 2, 10, 51, 2, 6, 19, 2, 17, 2, 43, 47, 2, 18, 2, 11, 21, 2, 6, 25, 2, 9, 59, 67, 50, 2, 6, 52, 60, 63, 63, 66, 63, 67, 67, 66, 66, 66, 65, 65, 58, 44, 2, 51, 47, 36, 2, 11, 2, 2, 2, 40, 2, 27, 2, 7, 47, 47, 46, 44, 18, 2, 7, 31, 44, 39, 45, 29, 2, 7, 29, 49, 53, 46, 47, 43, 48, 43, 39, 48, 49, 52, 49, 43, 38, 33, 2, 7, 36, 41, 44, 42, 49, 2, 7, 53, 44, 49, 52, 43, 48, 2, 22, 2, 21, 2, 7, 32, 42, 2, 7, 32, 2, 7, 45, 50, 27, 2, 7, 31, 11, 2, 19, 2, 65, 63, 63, 64, 2, 52, 41, 2, 7, 20, 2, 7, 38, 44, 20, 2, 7, 45, 40, 46, 21, 2, 7, 25, 42, 26, 2, 7, 14, 41, 2, 7, 45, 46, 43, 36, 47, 42, 49, 23, 2, 7, 27, 38, 28, 2, 7, 17, 49, 45, 47, 43, 42, 27, 2, 7, 29, 2, 7, 36, 44, 45, 44, 52, 37, 51, 50, 45, 47, 43, 51, 42, 28, 2, 7, 17, 2, 7, 11, 2, 7, 23, 2, 7, 16, 2, 7, 42, 28, 2, 7, 28, 37, 39, 38, 46, 54, 47, 46, 37, 43, 44, 21, 2, 7, 28, 2, 7, 39, 43, 25, 2, 7, 19, 2, 7, 48, 40, 39, 42, 43, 45, 42, 37, 45, 55, 40, 49, 52, 56, 45, 44, 21, 2, 7, 34, 2, 7, 46, 51, 51, 47, 49, 38, 52, 44, 46, 47, 44, 46, 30, 2, 7, 14, 44, 38, 40, 44, 45, 47, 51, 52, 18, 2, 7, 30, 47, 47, 54, 51, 47, 49, 47, 9, 44, 48, 53, 47, 44, 29, 2, 16, 2, 23, 2, 8, 41, 55, 2, 7, 20, 2, 8, 41, 50, 44, 53, 45, 53, 48, 46, 42, 53, 45, 48, 39, 38, 45, 49, 47, 17, 2, 7, 28, 2, 8, 19, 2, 7, 44, 42, 43, 50, 41, 49, 31, 2, 9, 2, 7, 25, 40, 43, 25, 2, 11, 2, 2, 2, 8, 2, 24, 2, 38, 2, 10, 59, 26, 2, 10, 64, 57, 2, 10, 65, 2, 10, 21, 2, 10, 60, 66, 63, 39, 2, 10, 38, 2, 10, 59, 66, 66, 64, 56, 2, 10, 18, 2, 10, 39, 2, 10, 53, 67, 2, 10, 59, 67, 62, 67, 28, 2, 10, 21, 2, 10, 39, 2, 10, 19, 2, 10, 62, 65, 63, 29, 2, 10, 8, 2, 10, 60, 31, 2, 10, 64, 2, 10, 60, 63, 61, 67, 2, 10, 65, 2, 10, 31, 2, 10, 24, 2, 10, 7, 2, 10, 22, 2, 44, 2, 10, 60, 61, 62, 61, 9, 2, 22, 2, 19, 2, 40, 35, 49, 43, 2, 6, 62, 15, 2, 6, 52, 2, 6, 63, 8, 2, 10, 10, 38, 36, 39, 35, 2, 22, 2, 6, 61, 64, 63, 64, 15, 2, 6, 20, 2, 6, 61, 67, 57, 20, 2, 6, 14, 2, 6, 61, 65, 64, 62, 7, 2, 10, 10, 36, 33, 36, 32, 2, 28, 2, 6, 61, 66, 65, 65, 65, 64, 65, 65, 64, 65, 65, 66, 11, 2, 6, 26, 2, 6, 39, 2, 6, 37, 2, 6, 63, 54, 2, 10, 12, 10, 36, 32, 2, 6, 50, 2, 10, 67, 36, 2, 6, 62, 52, 2, 10, 59, 2, 6, 32, 2, 10, 18, 2, 6, 18, 2, 10, 19, 2, 6, 27, 2, 10, 60, 2, 6, 58, 62, 64, 66, 57, 2, 10, 60, 39, 2, 6, 25, 2, 10, 60, 64, 15, 2, 6, 42, 2, 10, 59, 47, 2, 6, 6, 2, 10, 66, 2, 6, 18, 2, 10, 27, 2, 6, 16, 2, 10, 35, 2, 6, 19, 2, 10, 61, 15, 2, 6, 50, 2, 10, 60, 66, 64, 16, 2, 6, 27, 2, 10, 61, 67, 67, 38, 2, 6, 15, 2, 10, 61, 2, 6, 18, 2, 10, 60, 61, 27, 2, 6, 7, 2, 10, 12, 2, 6, 64, 65, 67, 64, 65, 64, 65, 60, 61, 67, 20, 2, 6, 23, 2, 6, 64, 2, 6, 10, 2, 6, 20, 2, 26, 2, 6, 19, 2, 6, 55, 63, 23, 2, 6, 50, 2, 6, 62, 61, 66, 63, 50, 47, 45, 51, 52, 50, 2, 59, 66, 2, 52, 47, 47, 42, 27, 2, 26, 2, 7, 21, 2, 6, 18, 27, 2, 7, 21, 2, 11, 41, 48, 50, 47, 48, 54, 43, 46, 21, 2, 7, 29, 2, 11, 18, 43, 40, 27, 2, 7, 25, 40, 52, 40, 26, 2, 6, 25, 2, 8, 32, 23, 51, 53, 33, 2, 7, 15, 43, 44, 47, 48, 25, 45, 45, 42, 18, 2, 6, 14, 24, 48, 52, 41, 18, 25, 2, 7, 26, 23, 2, 6, 24, 46, 43, 39, 45, 2, 7, 21, 2, 8, 17, 2, 6, 14, 2, 6, 25, 2, 61, 2, 6, 44, 38, 2, 8, 23, 2, 6, 42, 45, 45, 2, 7, 24, 2, 8, 31, 2, 6, 36, 62, 41, 43, 42, 42, 49, 43, 45, 47, 28, 2, 8, 23, 44, 38, 46, 32, 2, 6, 16, 42, 40, 38, 46, 2, 9, 2, 7, 45, 2, 17, 14, 54, 45, 48, 42, 40, 42, 2, 11, 2, 2, 2, 33, 2, 29, 2, 6, 50, 39, 2, 6, 23, 2, 6, 47, 46, 49, 47, 43, 55, 42, 29, 2, 6, 23, 2, 6, 19, 43, 43, 47, 41, 40, 49, 38, 44, 48, 47, 43, 42, 31, 2, 6, 16, 2, 6, 49, 42, 2, 6, 16, 2, 6, 45, 42, 42, 42, 41, 45, 44, 44, 29, 2, 6, 19, 2, 6, 41, 40, 52, 48, 41, 44, 47, 43, 44, 28, 2, 6, 22, 2, 6, 40, 39, 42, 46, 57, 47, 49, 23, 2, 6, 42, 2, 6, 50, 47, 37, 44, 43, 22, 2, 6, 27, 2, 6, 50, 52, 46, 42, 53, 54, 39, 18, 2, 6, 46, 42, 2, 6, 40, 46, 36, 34, 36, 49, 48, 26, 2, 6, 24, 2, 16, 2, 6, 49, 2, 6, 52, 2, 6, 19, 2, 6, 65, 65, 67, 42, 2, 6, 56, 41, 2, 6, 58, 45, 2, 6, 39, 2, 6, 56, 2, 6, 42, 2, 6, 55, 2, 6, 63, 65, 58, 11, 2, 6, 28, 39, 2, 6, 61, 57, 61, 66, 66, 47, 2, 6, 61, 65, 64, 67, 67, 64, 45, 2, 6, 46, 2, 6, 64, 15, 2, 6, 6, 2, 6, 67, 14, 2, 6, 48, 2, 6, 13, 2, 6, 59, 2, 6, 14, 2, 6, 33, 2, 6, 63, 30, 2, 6, 55, 2, 6, 60, 58, 2, 6, 60, 43, 2, 6, 20, 2, 6, 20, 2, 6, 39, 2, 6, 58, 60, 67, 63, 63, 23, 2, 6, 30, 2, 6, 61, 2, 6, 38, 2, 6, 59, 67, 62, 67, 66, 2, 6, 58, 59, 63, 46, 2, 6, 21, 2, 6, 58, 2, 6, 62, 59, 64, 65, 25, 2, 6, 33, 2, 6, 60, 2, 6, 37, 2, 6, 15, 2, 15, 2, 63, 13, 2, 6, 52, 2, 6, 67, 67, 63, 60, 64, 43, 2, 17, 2, 7, 59, 66, 65, 24, 2, 6, 64, 67, 22, 2, 7, 45, 2, 6, 16, 2, 7, 59, 34, 2, 6, 24, 2, 14, 2, 6, 36, 2, 6, 61, 67, 63, 2, 6, 22, 2, 6, 60, 32, 2, 6, 64, 41, 2, 6, 61, 65, 66, 65, 29, 2, 64, 12, 2, 7, 49, 2, 46, 2, 6, 50, 39, 53, 42, 18, 47, 45, 45, 39, 47, 44, 45, 43, 37, 24, 41, 47, 42, 22, 2, 7, 27, 49, 42, 42, 44, 39, 45, 43, 24, 2, 6, 22, 47, 29, 2, 7, 19, 2, 6, 47, 53, 25, 2, 7, 19, 2, 6, 19, 2, 7, 50, 21, 2, 6, 21, 50, 2, 7, 41, 50, 2, 7, 40, 2, 6, 52, 2, 25, 2, 6, 19, 2, 7, 46, 41, 42, 46, 49, 41, 46, 49, 42, 39, 51, 50, 39, 2, 6, 15, 2, 7, 16, 2, 14, 2, 6, 6, 2, 7, 5, 2, 6, 11, 2, 6, 29, 2, 7, 15, 2, 7, 52, 25, 2, 47, 2, 19, 2, 6, 48, 35, 2, 14, 2, 7, 33, 2, 7, 20, 2, 8, 34, 46, 44, 2, 6, 13, 2, 7, 25, 2, 8, 40, 2, 7, 50, 2, 6, 41, 2, 8, 29, 2, 7, 28, 2, 7, 19, 2, 7, 53, 2, 6, 46, 42, 38, 2, 7, 22, 2, 14, 2, 6, 23, 2, 7, 18, 2, 50, 45, 2, 7, 31, 2, 6, 18, 2, 20, 2, 6, 30, 2, 6, 48, 2, 6, 20, 2, 7, 46, 45, 2, 6, 21, 2, 7, 31, 2, 8, 52, 39, 2, 9, 2, 6, 41, 25, 2, 18, 2, 7, 45, 44, 44, 44, 42, 43, 45, 48, 2, 6, 28, 27, 2, 19, 2, 18, 19, 2, 7, 43, 2, 6, 48, 44, 19, 2, 14, 2, 7, 22, 39, 45, 48, 18, 2, 9, 2, 6, 47, 47, 48, 45, 48, 50, 37, 44, 21, 2, 6, 19, 43, 30, 2, 6, 19, 52, 38, 53, 42, 35, 50, 21, 2, 36, 2, 29, 2, 6, 51, 37, 22, 2, 6, 20, 47, 46, 39, 39, 50, 45, 2, 9, 2, 6, 54, 46, 32, 2, 17, 2, 58, 2, 7, 22, 2, 6, 26, 47, 2, 7, 45, 45, 37, 26, 2, 15, 22, 45, 53, 42, 45, 34, 2, 6, 21, 42, 44, 47, 49, 48, 40, 45, 48, 39, 45, 47, 39, 48, 16, 2, 7, 26, 39, 43, 47, 48, 2, 6, 43, 51, 43, 54, 29, 2, 7, 19, 42, 40, 52, 42, 25, 43, 47, 29, 2, 17, 2, 65, 24]\n"
     ]
    }
   ],
   "source": [
    "linelengths=[len(line) for line in open(\"hamlet.txt\")]#poor code as we dont close the file\n",
    "print linelengths"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(180718, 26.69394387001477, 26.0, 21.029872021427462)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum(linelengths), np.mean(linelengths), np.median(linelengths), np.std(linelengths)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "But perhaps we want to access Hamlet word by word and not line by line"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "31659"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hamletfile=open(\"hamlet.txt\")\n",
    "hamlettext=hamletfile.read()\n",
    "hamletfile.close()\n",
    "hamlettokens=hamlettext.split()#split with no arguments splits on whitespace\n",
    "len(hamlettokens)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "One can use the `with` syntax which cretaes a context. The file closing is then done automatically for us."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "31659\n"
     ]
    }
   ],
   "source": [
    "with open(\"hamlet.txt\") as hamletfile:\n",
    "    hamlettext=hamletfile.read()\n",
    "    hamlettokens=hamlettext.split()\n",
    "    print len(hamlettokens)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are roughly 32,000 words in Hamlet."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###The indexing of lists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "﻿XXXX\r\n",
      "HAMLET, PRINCE OF DENMARK\r\n",
      "\r\n",
      "by William Shakespeare\r\n",
      "\r\n",
      "\r\n",
      "\r\n",
      "\r\n",
      "PERSONS REPRESENTED.\r\n",
      "\r\n",
      "Claudius, King of Denmark.\r\n",
      "Hamlet, Son to the former, and Nephew to the present King.\r\n",
      "Polonius, Lord Chamberlain.\r\n",
      "Horatio, Friend to Hamlet.\r\n",
      "Laertes, Son to Polonius.\r\n",
      "Voltimand, Courtier.\r\n",
      "Cornelius, Courtier.\r\n",
      "Rosencrantz, Courtier.\r\n",
      "Guildenstern, Courtier.\r\n",
      "Osric, Courtier.\r\n",
      "A Gentleman, Courtier.\r\n",
      "A Priest.\r\n",
      "Marcellus, Officer.\r\n",
      "Bernardo, Officer.\r\n",
      "Francisco, a Soldier\r\n",
      "Reynaldo, Servant to Polonius.\r\n",
      "Players.\r\n",
      "Two Clowns, Grave-diggers.\r\n",
      "Fortinbras, Prince of Norway.\r\n",
      "A Captain.\r\n",
      "English Ambassadors.\r\n",
      "Ghost of Hamlet's Father.\r\n",
      "\r\n",
      "Gertrude, Queen of Denmark, and Mother of Hamlet.\r\n",
      "Ophelia, Daughter to Polonius.\r\n",
      "\r\n",
      "Lords, Ladies, Officers, Soldiers, Sailors, Messengers, and other\r\n",
      "Attendants.\r\n",
      "\r\n",
      "SCENE. Elsinore.\r\n",
      "\r\n",
      "\r\n",
      "\r\n",
      "ACT I.\r\n",
      "\r\n",
      "Scene I. Elsinore. A platform before the Castle.\r\n",
      "\r\n",
      "[Francisco at his post. Enter to him Bernardo.]\r\n",
      "\r\n",
      "Ber.\r\n",
      "Who's there?\r\n",
      "\r\n",
      "Fran.\r\n",
      "Nay, answer me: stand, and u\n"
     ]
    }
   ],
   "source": [
    "print hamlettext[:1000]#first 1000 characters from Hamlet."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "nd, in this upshot, purposes mistook\r\n",
      "Fall'n on the inventors' heads: all this can I\r\n",
      "Truly deliver.\r\n",
      "\r\n",
      "Fort.\r\n",
      "Let us haste to hear it,\r\n",
      "And call the noblest to the audience.\r\n",
      "For me, with sorrow I embrace my fortune:\r\n",
      "I have some rights of memory in this kingdom,\r\n",
      "Which now, to claim my vantage doth invite me.\r\n",
      "\r\n",
      "Hor.\r\n",
      "Of that I shall have also cause to speak,\r\n",
      "And from his mouth whose voice will draw on more:\r\n",
      "But let this same be presently perform'd,\r\n",
      "Even while men's minds are wild: lest more mischance\r\n",
      "On plots and errors happen.\r\n",
      "\r\n",
      "Fort.\r\n",
      "Let four captains\r\n",
      "Bear Hamlet like a soldier to the stage;\r\n",
      "For he was likely, had he been put on,\r\n",
      "To have prov'd most royally: and, for his passage,\r\n",
      "The soldiers' music and the rites of war\r\n",
      "Speak loudly for him.--\r\n",
      "Take up the bodies.--Such a sight as this\r\n",
      "Becomes the field, but here shows much amiss.\r\n",
      "Go, bid the soldiers shoot.\r\n",
      "\r\n",
      "[A dead march.]\r\n",
      "\r\n",
      "[Exeunt, bearing off the dead bodies; after the which a peal of\r\n",
      "ordnance is shot off.]\r\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print hamlettext[-1000:]#and last 1000 characters from Hamlet."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Lets split the word tokens. The first one below reads, give me the second, third, and fourth words (remember that python is 0 indexed). Try and figure what the others mean."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['HAMLET,', 'PRINCE', 'OF'] ['\\xef\\xbb\\xbfXXXX', 'HAMLET,', 'PRINCE', 'OF'] ﻿XXXX off.]\n"
     ]
    }
   ],
   "source": [
    "print hamlettokens[1:4], hamlettokens[:4], hamlettokens[0], hamlettokens[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['HAMLET,', 'OF', 'by', 'Shakespeare']"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hamlettokens[1:8:2]#get every 2nd world between the 2nd and the 9th: ie 2nd, 4th, 6th, and 8th"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "range and xrange get the list of integers upto N. But xrange behaves like an iterator. The reason for this is that there is no point generaing all os a million integers. We can just add 1 to the previous one and save memory. So we trade off storage for computation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mylist=[]\n",
    "for i in xrange(10):\n",
    "    mylist.append(i)\n",
    "mylist"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Dictionaries\n",
    "\n",
    "These are the bread and butter. You will use them a lot. They even duck like lists. But be careful how."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['three', 'two', 'one'] [('three', 3), ('two', 2), ('one', 1)] [3, 2, 1]\n"
     ]
    }
   ],
   "source": [
    "adict={'one':1, 'two': 2, 'three': 3}\n",
    "print [i for i in adict], [(k,v) for k,v in adict.items()], adict.values()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The keys do not have to be strings. From python 2.7 you can use dictionary comprehensions as well"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydict ={k:v for (k,v) in zip(alist, asquaredlist)}\n",
    "mydict"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can construct then nicely using the function `dict`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'a': 1, 'b': 2}"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict(a=1, b=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###and conversion to json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"1\": 1, \"2\": 4, \"3\": 9, \"4\": 16, \"5\": 25}\n"
     ]
    }
   ],
   "source": [
    "s=json.dumps(mydict)\n",
    "print s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{u'1': 1, u'2': 4, u'3': 9, u'4': 16, u'5': 25}"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "json.loads(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Strings\n",
    "\n",
    "Basically they behave like immutable lists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "off.]\n"
     ]
    }
   ],
   "source": [
    "lastword=hamlettokens[-1]\n",
    "print(lastword)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'str' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-25-55dfef3ad2e5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mlastword\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"k\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m: 'str' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "lastword[-2]=\"k\"#cant change a part of a string"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'.'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lastword[-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "You can join a list with a separator to make a string."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"\\xef\\xbb\\xbfXXXX,HAMLET,,PRINCE,OF,DENMARK,by,William,Shakespeare,PERSONS,REPRESENTED.,Claudius,,King,of,Denmark.,Hamlet,,Son,to,the,former,,and,Nephew,to,the,present,King.,Polonius,,Lord,Chamberlain.,Horatio,,Friend,to,Hamlet.,Laertes,,Son,to,Polonius.,Voltimand,,Courtier.,Cornelius,,Courtier.,Rosencrantz,,Courtier.,Guildenstern,,Courtier.,Osric,,Courtier.,A,Gentleman,,Courtier.,A,Priest.,Marcellus,,Officer.,Bernardo,,Officer.,Francisco,,a,Soldier,Reynaldo,,Servant,to,Polonius.,Players.,Two,Clowns,,Grave-diggers.,Fortinbras,,Prince,of,Norway.,A,Captain.,English,Ambassadors.,Ghost,of,Hamlet's,Father.,Gertrude,,Queen,of,Denmark,,and,Mother,of,Hamlet.,Ophelia,,Daughter,to,Polonius.,Lords,,Ladies,,Officers,,Soldiers,,Sailors,,Messengers,,and,other,Attendants.,SCENE.,Elsinore.,ACT,I.,Scene,I.,Elsinore.,A,platform,before,the,Castle.,[Francisco,at,his,post.,Enter,to,him,Bernardo.],Ber.,Who's,there?,Fran.,Nay,,answer,me:,stand,,and,unfold,yourself.,Ber.,Long,live,the,king!,Fran.,Bernardo?,Ber.,He.,Fra\""
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wierdstring=\",\".join(hamlettokens)\n",
    "wierdstring[:1000]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Functions\n",
    "\n",
    "Functions are even more the bread and butter. You'll see them as methods on objects, or standing alone by themselves."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(25, 125)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def square(x):\n",
    "    return(x*x)\n",
    "def cube(x):\n",
    "    return x*x*x\n",
    "square(5),cube(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<function square at 0x109a66500> <type 'function'>\n"
     ]
    }
   ],
   "source": [
    "print square, type(cube)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In Python, functions are \"first-class\". This is just a fancy way of saying, you can pass functions to other functions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3 4 <function square at 0x109a66500>\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def sum_of_anything(x,y,f):\n",
    "    print x,y,f\n",
    "    return(f(x) + f(y))\n",
    "sum_of_anything(3,4,square)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Python functions can have positional arguments and keyword arguments. Positional arguments are stored in a tuple, and keyword arguments in a dictionary. Note the \"starred\" syntax"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "got 1 3 () {}\n",
      "1\n",
      "got 1 3 (4,) {'c': 2, 'd': 1}\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "def f(a,b,*posargs,**dictargs):\n",
    "    print \"got\",a,b,posargs, dictargs\n",
    "    return a\n",
    "print f(1,3)\n",
    "print f(1,3,4,d=1,c=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ">**YOUR TURN** create a dictionary with keys the integers upto and including 10, and values the cubes of these dictionaries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#your code here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Booleans and Control-flow\n",
    "\n",
    "Lets test for belonging..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a=[1,2,3,4,5]\n",
    "1 in a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "6 in a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Python supports if/elif/else clauses for multi-way conditionals"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "One\n"
     ]
    }
   ],
   "source": [
    "def do_it(x):\n",
    "    if x==1:\n",
    "        print \"One\"\n",
    "    elif x==2:\n",
    "        print \"Two\"\n",
    "    else:\n",
    "        print x\n",
    "do_it(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Two\n",
      "3\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(None, None)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "do_it(2), do_it(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can `break` out of a loop based on a condition. The loop below is a for loop."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n"
     ]
    }
   ],
   "source": [
    "for i in range(10):\n",
    "    print i\n",
    "    if (i > 5):\n",
    "        break"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "While loops are also supported. `continue` continues to the next iteration of the loop skipping all the code below, while `break` breaks out of it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "i=0\n",
    "while i < 10:\n",
    "    print i\n",
    "    i=i+1\n",
    "    if i < 5:\n",
    "        continue\n",
    "    else:\n",
    "        break\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Exceptions\n",
    "\n",
    "This is the way to catch errors."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(<type 'exceptions.TypeError'>, TypeError('f() takes at least 2 arguments (1 given)',), <traceback object at 0x109a75050>)\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    f(1)#takes atleast 2 arguments\n",
    "except:\n",
    "    import sys\n",
    "    print sys.exc_info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## All together now\n",
    "\n",
    "Lets see what hamlet gives us. We convert all words to lower-case"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "95"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hamletlctokens=[word.lower() for word in hamlettokens]\n",
    "hamletlctokens.count(\"thou\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then find a unique set of words using python's `set` data structure. We count how often those words occured usinf the `count` method on lists."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "uniquelctokens=set(hamletlctokens)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "tokendict={}\n",
    "for ut in uniquelctokens:\n",
    "    tokendict[ut]=hamletlctokens.count(ut)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We find the 100 most used words..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('the', 1136),\n",
       " ('and', 943),\n",
       " ('to', 720),\n",
       " ('of', 667),\n",
       " ('a', 527),\n",
       " ('my', 512),\n",
       " ('i', 510),\n",
       " ('in', 420),\n",
       " ('you', 412),\n",
       " ('ham.', 358),\n",
       " ('that', 337),\n",
       " ('it', 324),\n",
       " ('is', 320),\n",
       " ('his', 295),\n",
       " ('not', 270),\n",
       " ('with', 264),\n",
       " ('this', 250),\n",
       " ('your', 241),\n",
       " ('for', 231),\n",
       " ('but', 228),\n",
       " ('as', 216),\n",
       " ('he', 202),\n",
       " ('be', 201),\n",
       " ('what', 183),\n",
       " ('have', 174),\n",
       " ('will', 149),\n",
       " ('so', 143),\n",
       " ('me', 142),\n",
       " ('we', 132),\n",
       " ('do', 128),\n",
       " ('are', 126),\n",
       " ('him', 122),\n",
       " ('our', 119),\n",
       " ('king.', 113),\n",
       " ('by', 111),\n",
       " ('hor.', 110),\n",
       " ('or', 109),\n",
       " ('if', 109),\n",
       " ('on', 109),\n",
       " ('no', 107),\n",
       " ('shall', 106),\n",
       " ('thou', 95),\n",
       " ('all', 95),\n",
       " ('from', 95),\n",
       " ('they', 93),\n",
       " ('let', 92),\n",
       " ('good', 88),\n",
       " ('at', 86),\n",
       " ('thy', 86),\n",
       " ('pol.', 86),\n",
       " ('how', 84),\n",
       " ('most', 82),\n",
       " ('lord,', 81),\n",
       " ('her', 76),\n",
       " ('more', 76),\n",
       " ('queen.', 76),\n",
       " ('like', 75),\n",
       " ('would', 74),\n",
       " ('was', 73),\n",
       " (\"'tis\", 70),\n",
       " ('you,', 66),\n",
       " ('may', 65),\n",
       " ('very', 64),\n",
       " ('laer.', 62),\n",
       " ('hath', 62),\n",
       " ('[enter', 61),\n",
       " ('lord.', 60),\n",
       " ('did', 59),\n",
       " ('give', 58),\n",
       " ('must', 58),\n",
       " ('oph.', 58),\n",
       " ('their', 57),\n",
       " ('o,', 57),\n",
       " ('know', 57),\n",
       " (\"i'll\", 56),\n",
       " ('an', 55),\n",
       " ('should', 55),\n",
       " ('which', 55),\n",
       " ('some', 54),\n",
       " ('when', 54),\n",
       " ('come', 54),\n",
       " ('upon', 53),\n",
       " ('make', 53),\n",
       " ('am', 52),\n",
       " ('such', 51),\n",
       " ('ros.', 51),\n",
       " ('than', 51),\n",
       " ('there', 50),\n",
       " ('where', 49),\n",
       " ('now', 48),\n",
       " ('go', 48),\n",
       " ('o', 46),\n",
       " ('us', 46),\n",
       " ('clown.', 45),\n",
       " ('much', 44),\n",
       " ('had', 44),\n",
       " ('these', 44),\n",
       " ('them', 44),\n",
       " ('she', 43),\n",
       " ('out', 43)]"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "L=sorted(tokendict.iteritems(), key= lambda (k,v):v, reverse=True)[:100]\n",
    "L"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Lets get the top 20 of this and plot a bar chart!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('the', 1136), ('and', 943), ('to', 720), ('of', 667), ('a', 527), ('my', 512), ('i', 510), ('in', 420), ('you', 412), ('ham.', 358), ('that', 337), ('it', 324), ('is', 320), ('his', 295), ('not', 270), ('with', 264), ('this', 250), ('your', 241), ('for', 231), ('but', 228)]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAegAAAFVCAYAAAAkBHynAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XtcVHXi//H3cNNgwMTQVIyUyOwCLYmleW1bc7ceVhYV\nGGyPtUxbXQu3stLQpGwzYy3dtLRsJ1dlW9pqu2wbm+GltLatbC0zKqQbqGjNDMoMzvz+6Ov8vAIz\nzNEP8Hr+pWfOvM9nPszhzTlnLja/3+8XAAAwSsTxHgAAADgcBQ0AgIEoaAAADERBAwBgIAoaAAAD\nUdAAABioyYL+8MMPlZeXJ0n65JNPNHbsWOXl5WncuHHauXOnJKmkpERXXXWVrr32Wq1evVqStHfv\nXk2ePFljx47V+PHjVVtba92jAACgjWm0oJ988klNnz5dXq9XkvTAAw9oxowZcjgcGjlypJ588knt\n2LFDDodDK1eu1NKlSzVv3jx5PB6tWLFCffv21fLly3XFFVfo8ccfPyYPCACAtqDRgk5JSdGCBQu0\n/7NMHnnkEZ1xxhmSpIaGBnXo0EEfffSRMjMzFR0dLbvdrpSUFG3ZskXvv/++hg4dKkkaMmSI3n77\nbYsfCgAAbUejBT1y5EhFRkYG/p+UlCRJev/997V8+XLdcMMNcrlcio+PD6wTFxcnl8sll8uluLi4\nwDKn02nF+AEAaJOigr3DK6+8okWLFumJJ55Q586dZbfb5Xa7A7e73W7Fx8cftNztdishIaHJ7IaG\nfYqKimxyPQAA2rqgCvqFF15QSUmJHA6HOnXqJElKT09XcXGxPB6P6uvrVVFRodNPP12ZmZkqLy9X\nenq6ysvL1b9//ybzd+2qa3KdpKR4bd8e/qNxq3KtzG5tuVZmk2t9dmvLtTK7teVamd3acq3MDiU3\nKSn+qLc1q6BtNpt8Pp8eeOAB9ejRQ5MmTZIknX/++Zo0aZLy8/OVm5srn8+ngoICxcTEKCcnR3fe\neadyc3MVEx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nzp2aNGnSYXkf\nfPCBxo0bp9raWuXk5CghIUF/+ctf1NDQIJvNpgULFuizzz7TE088oZiYGH3//fe67rrr9M477+jT\nTz9Vfn5+oz/Ppva7Z599Vv/617+0Z88ede7cWQsWLAg81//0pz/plltuCXqeH3roIdXV1amgoEAL\nFiwI6v6N5X7xxRf6/PPP5Xa7tWfPHt12221BHTUe6MB5v+6667R48WK99tprWr16tZYsWaKoqCh1\n7dpVxcXFzf7lXVpaqrfeekv19fXatm2bbrrpJvXt21dFRUWKjIxUTEyMioqKtHbtWu3YsaPJ+Rkz\nZoyWLFmi+Ph4nX/++Vq+fLn69eunAQMGqGfPnioqKtKaNWv0ySef6LTTTpPH49HUqVP13Xff6cQT\nT9Sjjz6qqKgj10FTz4sLL7xQ69at0/Lly/XCCy8oIiJCZ599tqZPn37U8bZk37jyyis1YcIEnXji\niRo2bJhuvPHGo26nsLBQlZWVuvfee1VTUyOXy3XQ7+LLLrtMvXv3VnR0tB555JFm/ewkae3atXrr\nrbdUV1enSZMmadasWXrttdcUExOjhx9+WKmpqaqurtbu3bt133336d5772129oGMLOiJEydq69at\nGjJkiKqrqzV79mxt3LhRS5YsUWZmphYsWKDS0lJ16NBBd9xxh9avX69BgwY1mrlt2zZdeuml+sUv\nfqGamhpdf/316tatmzIyMnT33XeruLhY//jHP3ThhRdqw4YNKi0tVX19vS677LKQx+9yuTR48GDl\n5eWpurpaubm5KisrC3VatGrVKp100kl6+OGH5Xa7NWbMGI0YMUKnn356i8tZOniOqqurm/yF3pi6\nujotXbpUr7zyipYtW6aSkhJt2LBBy5YtU2VlpX788UdVV1crMTGxReUshf/o0mazyWaz6auvvtLT\nTz+tjh076uKLL9bOnTvVpUuXZudcc801WrFihYYNG6bnnntOGRkZcjqdmjt3buDnN3DgwGY9Fr/f\nr+joaC1dulTffPONxo8fr8svv1xPPPGEOnbsqHvvvVdr165Vt27dVF1drRdeeEEff/yxpkyZojfe\neEPff/+9Jk2a1OjPs7H9bvjw4dq9e7eWL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IyMvTII48c8Y/6xp7rjT0vDnT66acrNzdXcXFxOvnkk496yny/luwbweybNptNN998\ns+6+++7A7+L77rtPkZGRIe3jNptNu3fv1q9//Wvt2bNHRUVF2rZtm8aPH6+ePXsedBCWmpqqO+64\nQw899FDQ25H4LG4cJxMnTtTdd9+tXr16He+hWKqmpkZ33nmnnn766eM9FMAo7BtNM/IUN9quvXv3\nasyYMerTp0+bL+fXX39d48aN0+9+97vjPRTAKOwbzcMRNAAABuIIGgAAA1HQAAAYiIIGAMBAFDQA\nAAaioAEAMND/A8NudfT377dBAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x109a70ad0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "topfreq=L[:20]\n",
    "print topfreq\n",
    "pos = np.arange(len(topfreq))\n",
    "plt.bar(pos, [e[1] for e in topfreq]);\n",
    "plt.xticks(pos+0.4, [e[0] for e in topfreq]);"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
